##Function to create two histograms
histo <- function(x, y){
    h_t_wxt <- histogram(~x)
    h_st_wxt <- histogram(~y)
    h_h <- c(h_t_wxt, h_st_wxt, layout(1, 2))
    return(print(h_h))
}
  
##read data
Data <- read.csv("C:/Users/Steffi/Documents/=Uni/SpezPhy/Qualit??tskontrolleEinzelneStationen/dataset_single_qc.csv")

##create two histograms
histo(Data$t_wxt, Data$st_wxt)

##***********************Impossible Values**************************************
##Mean value
Mean_t <- mean(Data$t_wxt, na.rm = FALSE)
Mean_st <- mean(Data$st_wxt, na.rm = FALSE)

##standard deviation
Sd_t <- sd(Data$t_wxt)
Sd_st <- sd(Data$st_wxt)

##give these values, who are bigger or smaler than 2Sd
Data_subset_t <- subset(Data, Data$t_wxt > (Mean_t + 2 * Sd_t))
Data_subset_t2 <- subset(Data, Data$t_wxt < (Mean_t - 2 * Sd_t))

Data_subset_st <- subset(Data, Data$st_wxt > (Mean_st + 2  * Sd_st))
Data_subset_st2 <- subset(Data, Data$st_wxt < (Mean_st - 2 * Sd_st))

##error values
ErrorVal_t <- c(Data_subset_t, Data_subset_t2)
ErrorVal_st <- c(Data_subset_st, Data_subset_st2)
              
##*************************very unusual values**********************************
##Meadian value

Med_t <- median(Data$t_wxt)
Med_st <- median(Data$st_wxt)
              
##Tja, wie geht das denn jetzt, dass die ??u??ersten 2,5% bzw. 0,5% 
##herausgefiltert werden?

##************************consistency check*************************************
##change into integer values
as.integer(Data$t_wxt)
as.integer(Data$st_wxt)   ##wieso spuckt er denn immernoch neg. Werte aus?


diff(Data$t_wxt, Data$st_wxt) ##mit der Funktion werden die Differenzen gebildet
##dann muss man sich ??berlegen welche Unterschiede "ok" und welche zu gro?? sind,
##um diejenigern Werte rauszuwerfen


